package com.tbsoft.ehr.dao.serviceCustomer;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.tbsoft.ehr.dao.BaseDaoImpl;
import com.tbsoft.ehr.model.ServiceCustomer;

public class ServiceCustomerDaoImpl extends BaseDaoImpl<ServiceCustomer>
		implements ServiceCustomerDao {

	@SuppressWarnings("unchecked")
	public List<ServiceCustomer> getServiceCustomers() {

		return getHibernateTemplate().executeFind(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				return session.createQuery("from ServiceCustomer sc where sc.status<>'D'").list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	public List<ServiceCustomer> getServiceCustomerByName(final String name) {
	
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query q = session.createQuery("from ServiceCustomer sc where sc.name=?");
				 q.setString(0, name);
				 return q.list();
			}
		});		
		
	}

	public ServiceCustomer getServiceCustomerById(String id) {
		return (ServiceCustomer)this.getHibernateTemplate().get(ServiceCustomer.class, id);
	}

}
